﻿using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Configuration;
using ShareMarking.Systems.Entity;

namespace ShareMarking.Systems.Service
{
    public partial class BasePage : System.Web.UI.Page
    {
        protected internal siteconfig config = siteconfigService.Instance.loadConfig();
        /// <summary>
        /// 父类的构造函数
        /// </summary>
        public BasePage()
        {
            //是否关闭网站
            if (config.webstatus == 0)
            {
                HttpContext.Current.Response.Redirect(config.webpath + "error.aspx?msg=" + Utils.UrlEncode(config.webclosereason));
                return;
            }
            ShowPage();
        }

        /// <summary>
        /// 页面处理虚方法
        /// </summary>
        protected virtual void ShowPage()
        {
            //虚方法代码
        }

        #region 页面通用方法==========================================

        /// <summary>
        /// 返回分页字符串
        /// </summary>
        /// <param name="pagesize">页面大小</param>
        /// <param name="pageindex">当前页</param>
        /// <param name="totalcount">记录总数</param>
        /// <param name="_key">URL映射Name名称</param>
        /// <param name="_params">传输参数</param>
        protected string get_page_link(int pagesize, int pageindex, int totalcount, string _key, params object[] _params)
        {
            return Utils.OutPageList(pagesize, pageindex, totalcount, String.Empty, 8);
        }

        /// <summary>
        /// 返回分页字符串
        /// </summary>
        /// <param name="pagesize">页面大小</param>
        /// <param name="pageindex">当前页</param>
        /// <param name="totalcount">记录总数</param>
        /// <param name="linkurl">链接地址</param>
        protected string get_page_link(int pagesize, int pageindex, int totalcount, string linkurl)
        {
            return Utils.OutPageList(pagesize, pageindex, totalcount, linkurl, 8);
        }

        /// <summary>
        /// 返回指定大小的图片
        /// </summary>
        /// <param name="oldrul">原始地址</param>
        /// <param name="width">长</param>
        /// <param name="height">高</param>
        /// <returns>新地址</returns>
        protected string imgurl(string oldrul, int width, int height)
        {
            var type = "jpg";
            if(oldrul.ToLower().Contains("jpg"))
            {
                type = "jpg";
            }
            else if (oldrul.ToLower().Contains("jpeg"))
            {
                type = "jpeg";
            }
            else if (oldrul.ToLower().Contains("gif"))
            {
                type = "gif";
            }
            else if (oldrul.ToLower().Contains("png"))
            {
                type = "png";
            }
            else if (oldrul.ToLower().Contains("bmp"))
            {
                type = "bmp";
            }
            return string.Format(oldrul + "_{0}x{1}.{2}", width, height, type);
        }

        #endregion    
    }
}
